<?php
/**
 * Created by PhpStorm.
 * User: BlueIdeaLirui
 * Date: 2019/09/16
 * Time: 14:22
 */

namespace common\utils;

class RedisUtil
{
    const CACHE_KEY = '';

    public static function map2RedisParameter($map)
    {
        $temp = [];
        foreach ($map as $k => $v) {
            $temp[] = $k;
            $temp[] = !is_array($v) ? $v : serialize($v);
        }
        return $temp;
    }

    public static function RedisMapList2Map($list)
    {
        $temp = [];
        for ($i = 0; $i < count($list); $i = $i + 2) {
            $value = @unserialize($list[$i + 1]);
            $temp[$list[$i]] = !empty($value) ? $value : (!is_array(@unserialize($list[$i + 1])) ? $list[$i + 1] : []);
        }
        return $temp;
    }

    public static function RedisFilterList($data = [])
    {
        $list = [];
        if (!empty($data)) {
            foreach ($data as $item) {
                $list[] = static::RedisMapList2Map($item);
            }
        }

        return $list;
    }
}
